package jeme.math;

import java.math.BigInteger;

/**
 * Represents a rational number in Scheme. A rational number is made up of a 
 * numerator and denominator.
 * 
 * @author Erik Silkensen (silkense@colorado.edu)
 * @version Jan 7, 2009
 */
public class SchemeRational extends SchemeReal 
{
    /**
     * Subclasses are allowed to take responsibility of initializing themselves
     * by using default constructors all of the way up the tower.
     */
    protected SchemeRational() 
    {

    }

    /**
     * Creates a rational number with the specified numerator and denominator.
     * 
     * @param numerator  the numerator of this number
     * @param denominator  the denominator of this number
     */
    public SchemeRational(SchemeInteger numerator, SchemeInteger denominator) 
    {
        super(numerator, denominator);
    }
    
    /**
     * Returns whether or not this number is rational.
     * 
     * @return  <code>true</code>
     */
    public boolean isRational() 
    {
        return true;
    }

    /**
     * Returns whether or not this number is an integer.  A rational is an 
     * integer if and only if its denominator is one.
     * 
     * @return  <code>true</code> if this number is an integer, else 
     *     <code>false</code>
     */
    public boolean isInteger() 
    {
        BigInteger denomerator = getDenominator().getValue();
        return denomerator.compareTo(BigInteger.ONE) == 0;
    }

    /**
     * Returns a rational version of this number.
     * 
     * @return  <code>this</code>
     */
    public SchemeRational toRational() 
    {
        return this;
    }
}
